<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Title  Merchnat model
 * */


class merchant extends CI_Model
{

	/**
	 * Holds an array of tables used
	 *
	 * @var string
	 **/
	public $mastables = array();


	/**
	 * __construct
	 *
	 **/
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	
	public function get_merchnt_details($data=array('Email'=>'','Password'=>'','ClientID'=>'','IsActive'=>''))
	{
		$this->db->from('client as a');
		$this->db->join('business as b','a.BussinessID=b.BusinessID','inner');
		$this->db->join('currency as c','b.CurrencyID=c.CurrencyID','left');
		if(isset($data['Email']) && $data['Email'])
		{
			$this->db->where('a.Email',$data['Email']);
		}
		if(isset($data['Password']) && $data['Password'])
		{
			$this->db->where('a.Password',$data['Password']);
		}
		if(isset($data['ClientID']) && $data['ClientID'])
		{
			$this->db->where('a.ClientID',$data['ClientID']);
		}
		if(isset($data['IsActive']))
		{
			$this->db->where('a.IsActive',$data['IsActive']);
		}
		$this->db->limit(1);
		$query = $this->db->get();
		$result = $query->result_array();
		return $result;
	}
	
	
	public function create_business($business=array())
	{
		if(is_array($business) && count($business)>0)
		{
			$this->db->insert('business', $business);
			return $this->db->insert_id();
		}
		else return FALSE;
	}
	
	public function create_client($client=array())
	{
		if(is_array($client) && count($client)>0)
		{
			$this->db->insert('client', $client);
			return $this->db->insert_id();
		}
		else return FALSE;
	}
	
	public function add_business_attributes($array)
	{
		if(is_array($array) && count($array)>0)
		{
			$this->db->insert('business_attribute', $array);
			return $this->db->insert_id();
		}
		else return FALSE;
	}
	
	public function add_business_attributes_values_as_batch($array)
	{
		return $this->db->insert_batch('business_attribute_value', $array);
	}
	
	public function get_business_attributes($data=array('BusinessID'=>''))
	{
		$this->db->from('business_attribute');
		$this->db->where('BusinessID',$data['BusinessID']);
		$this->db->where('IsActive',1);
		$this->db->order_by('Order');
		$query = $this->db->get();
		return $result = $query->result_array();
	}
	
	public function get_business_attributes_values($data=array('AttributeID'=>''))
	{
		if(!empty($data))
		{
			
			$this->db->from('business_attribute_value');
			$this->db->where('AttributeID',$data['AttributeID']);
			$this->db->where('IsActive',1);
			$this->db->order_by('Order');
			$query = $this->db->get();
			return $result = $query->result_array();
		}
		else return FALSE;
	}
}